package cn.tedu.charging.user.service.impl;

import cn.tedu.charging.user.dao.repository.VehicleRepository;
import cn.tedu.charging.user.pojo.po.VehiclePO;
import cn.tedu.charging.user.pojo.vo.VehicleVO;
import cn.tedu.charging.user.service.VehicleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class VehicleServiceImpl implements VehicleService {
    private VehicleRepository vehicleRepository;
    public VehicleServiceImpl(VehicleRepository vehicleRepository) {
        this.vehicleRepository = vehicleRepository;
    }
    @Override
    public List<VehicleVO> listUserVehicles(Integer userId) {
        List<VehiclePO> sourceList = vehicleRepository.selectUserVehicles(userId);
        List<VehicleVO> targetList=new ArrayList<>();
        sourceList.forEach((item)->{
            VehicleVO target=new VehicleVO();
            BeanUtils.copyProperties(item,target);
            targetList.add(target);
        });
        return targetList;
    }
}
